package com.songjia.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.client.RestTemplate;

import com.songjia.springcloud.annotation.ExcludeComponentScan;
import com.songjia.springcloud.config.RibbonConfiguration;

/**
 * 
 * 
 * @Description: Ribbon服务消费者
 *
 * @author: songjia
 * @date: 2019年4月17日 下午3:44:08
 */
@SpringBootApplication
@EnableEurekaClient // 标识为Eureka客户端
// 扫描的时候排除标注了ExcludeComponent注解的类
@ComponentScan(excludeFilters = { @Filter(type = FilterType.ANNOTATION, classes = { ExcludeComponentScan.class }) })
// 访问“eureka-client”服务的时候，使用自定义的负载均衡策略类RibbonConfiguration
@RibbonClient(name = "eureka-client", configuration = RibbonConfiguration.class)
@EnableCircuitBreaker // 开启断路器功能
public class DeptRibbonApplication {
	public static void main(String[] args) {
		SpringApplication.run(DeptRibbonApplication.class, args);
	}

	@Bean
	@LoadBalanced // 使用LoadBalanced开启客户端负载均衡的功能
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}
}
